package com.netease.nie.service;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.dao.UserDao;
import com.netease.nie.model.User;

/**
 * 
 * @author wwbn3695
 * @createDate July 22nd,2016
 *
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	
	public Long queryUserIdBySsn(String ssn) {
		Long userId = userDao.queryUserIdBySsn(ssn);
		return userId;
	}

	public Long registerUser(User user) throws Exception {
		// 处理mobile字段
		String mobile = user.getMobile();
		if (StringUtils.isNotBlank(mobile)) {
			if (mobile.startsWith("N")) {
				user.setMobile(null);
			} else if (mobile.startsWith("O")) {
				user.setMobile(mobile.substring(1));
			}
		} else {
			user.setMobile(null);
		}
		
		return userDao.registerUser(user);
	}

}
